home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekikoh Dennoh Club 3
/
Gekikoh Dennoh Club Vol. 3 (Japan).7z
/
Gekikoh Dennoh Club Vol. 3 (Japan) (Track 1).bin
/
cone
/
mi506dc
/
pzau.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-02-19
|
4KB
|
213 lines
/*
パワーザウルスのバックアップイメージからデジカメデータを抽出する
by 電魔団\shoryu 1998
*/
#include <stdio.h>
#include <doslib.h>
#include <io.h>
int startPos[1024]; //max=1/16VGA normal 438
//min=VGA fine 36
char tarDrv[3]="P:"; //@:
char tarName[256]="\\__ZAURUS\\PAINT1.BOX"; //ファイル名は固定でよかろう
char *tarBuf;
/*
JFIFのヘッダサーチ&ライト
*/
int main(argc,argv)
int argc;
char *argv[];
{
FILE *fp,*ofp;
char *fileName,fileNameBuf[256];
int len,st;
int pos,count,mcount;
if( Init(argc,argv)<0 ){
goto quick_exit;
}
fileName=fileNameBuf;
strcpy(fileName,tarDrv);
strcat(fileName,tarName);
fp=fopen(fileName,"rb");
if( fp==NULL ){
printf("open err:%s\n",fileName);
goto quick_exit;
}
len=filelength(fileno(fp));
tarBuf=MALLOC(len);
if( (int)tarBuf<0 ){ //オンメモリで実行可能か?
// printf("メモリ不足");
fclose(fp); //いったんファイルを閉じて、
main2(argc,argv); //少メモリ版実行
goto quick_exit;
}
printf("フォトメモリーデータ読み込み中…\n");
fread(tarBuf,sizeof(char),len,fp);
fclose(fp);
printf("解析中…\n"); //動けばよしとす
count=0;
startPos[count++]=0;
for( pos=0;pos<len-4;pos++ ){
if( tarBuf[pos]=='J' ){
if( tarBuf[pos+1]=='F' &&tarBuf[pos+2]=='I' &&tarBuf[pos+3]=='F' ){
/**/ printf("\x0d%d",pos);
startPos[count++]=pos;
}
}
}
startPos[count]=len;
mcount=count;
for( count=1;count<mcount;count++ ){
sprintf(fileName,"PZAU%04d.JPG",count);
/**/ printf("\x0d%s",fileName);
ofp=fopen(fileName,"wb");
//JPEGへっだ部書き込み
st=0;
len=startPos[1]-4;
fwrite(tarBuf+st,sizeof(char),len,ofp);
//JPEGデータ部書き込み
st=startPos[count]-4;
len=startPos[count+1]-startPos[count]+1;
fwrite(tarBuf+st,sizeof(char),len,ofp);
fclose(ofp);
}
printf("\n");
quick_exit:
;
}
/*
少メモリ
*/
int main2(argc,argv)
int argc;
char *argv[];
{
FILE *fp,*ofp;
char *fileName,fileNameBuf[256];
int len,st;
int pos,lpos,count,mcount;
fileName=fileNameBuf;
strcpy(fileName,tarDrv);
strcat(fileName,tarName);
fp=fopen(fileName,"rb");
if( fp==NULL ){
printf("open err:%s\n",fileName);
goto quick_exit;
}
len=filelength(fileno(fp));
tarBuf=MALLOC(256*1024); //てきとーにワークを確保:256Kあればいいでしょ
if( (int)tarBuf<0 ){
printf("err:メモリ不足\n");
goto quick_exit;
}
printf("解析中…\n");
count=0;
startPos[count++]=0;
for( pos=0;pos<len-4;pos+=(32*1024-16) ){
fseek(fp,pos,SEEK_SET);
fread(tarBuf,sizeof(char),32*1024,fp); //読み込みは32K
for( lpos=0;lpos<32*1024-4;lpos++ ){
if( tarBuf[lpos]=='J' ){
if( tarBuf[lpos+1]=='F' &&tarBuf[lpos+2]=='I' &&tarBuf[lpos+3]=='F' ){
printf("\x0d%d",pos+lpos);
startPos[count++]=pos+lpos;
}
}
}
}
startPos[count]=len;
mcount=count;
for( count=1;count<mcount;count++ ){
sprintf(fileName,"PZAU%04d.jpg",count);
ofp=fopen(fileName,"wb");
/**/ printf("\x0d%s",fileName);
//JPEGへっだ書き込み
st=0;
len=startPos[1]-4;
fseek(fp,st,SEEK_SET);
fread(tarBuf,sizeof(char),len,fp);
fwrite(tarBuf,sizeof(char),len,ofp);
//JPEGデータ書き込み
st=startPos[count]-4;
len=startPos[count+1]-startPos[count]+1;
fseek(fp,st,SEEK_SET);
fread(tarBuf,sizeof(char),len,fp);
fwrite(tarBuf,sizeof(char),len,ofp);
fclose(ofp);
}
fclose(fp);
printf("\n");
quick_exit:
exit();
}
/*
エラー:0未満
*/
int Init(argc,argv)
int argc;
char *argv[];
{
int res=0;
if( argc!=2 ){
printf(
"X680x0 PowerZAURUS JPEGファイル変換ユーティリティー\n"
"PowerZAURUS のフォトメモリーデータをJPEGファイルに変換し、\n"
"カレントにPZAU????.JPGとして出力します\n"
"使用方法:@>PZAU drive\n"
" drive :PCカードドライブ(P:などで指定)\n"
);
res=-1;
}
else{
strcpy(tarDrv,argv[1]);
}
return(res);
}
/* [ EOF ] */